using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Refit;
using ZhaoXi.MSACommerce.CommonServiceClient;
using Zhaoxi.MSACommerce.OrderService.UseCases.Api;
using Zhaoxi.MSACommerce.OrderService.UseCases.Service;
using ZhaoXi.MSACommerce.UserCases.Common;

namespace Zhaoxi.MSACommerce.OrderService.UseCases;

public static class DependencyInjection
{
    public static IServiceCollection AddUseCase(this IServiceCollection services)
    {
        services.AddUserCaseCommon(Assembly.GetExecutingAssembly());
        ConfigureUserService(services);
        
     
        
        services.AddRefitClient<IProductClient>()
            .ConfigureHttpClient(client =>
            {
                client.BaseAddress = new Uri("http://localhost:5037"); 
                client.Timeout = TimeSpan.FromSeconds(30);
            });
        
        return services;
    }
    
    private static void ConfigureUserService(IServiceCollection services)
    {
        services.AddServiceClient<ProductClient>(option =>
        {
            option.LoadBalancingStrategy = LoadBalancingStrategy.RoundRobin;
        }, client =>
        {
            client.Timeout = TimeSpan.FromSeconds(1);
        });
    }
    
}